package com.newjiabo.web.controller.ski;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.newjiabo.common.annotation.RepeatSubmit;
import com.newjiabo.common.core.domain.entity.SkiMember;
import com.newjiabo.ski.service.ISkiMemberService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.newjiabo.common.annotation.Log;
import com.newjiabo.common.core.controller.BaseController;
import com.newjiabo.common.core.domain.AjaxResult;
import com.newjiabo.common.enums.BusinessType;
import com.newjiabo.common.utils.poi.ExcelUtil;
import com.newjiabo.common.core.page.TableDataInfo;

/**
 * 会员Controller
 *
 * @author ruoyi
 * @date 2023-09-25
 */
@Api(tags = "后台;小程序用户管理")
@RestController
@RequestMapping("/system/member")
public class SkiMemberController extends BaseController {
    @Autowired
    private ISkiMemberService skiMemberService;

    /**
     * 查询会员列表
     */
    @ApiOperation(value = "查询会员列表")
    @PreAuthorize("@ss.hasPermi('system:member:list')")
    @GetMapping("/list")
    public TableDataInfo list(SkiMember skiMember) {
        startPage();
        List<SkiMember> list = skiMemberService.selectSkiMemberList(skiMember);
        return getDataTable(list);
    }

    /**
     * 导出会员列表
     */
    @ApiOperation(value = "导出会员列表")
    @PreAuthorize("@ss.hasPermi('system:member:export')")
    @Log(title = "导出会员列表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SkiMember skiMember) {
        List<SkiMember> list = skiMemberService.selectSkiMemberList(skiMember);
        ExcelUtil<SkiMember> util = new ExcelUtil<SkiMember>(SkiMember.class);
        util.exportExcel(response, list, "会员数据");
    }

    /**
     * 获取会员详细信息
     */
    @ApiOperation(value = "获取会员详细信息")
    @PreAuthorize("@ss.hasPermi('system:member:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success(skiMemberService.selectSkiMemberById(id));
    }

    /**
     * 新增会员
     */
    @ApiOperation(value = "新增会员")
    @PreAuthorize("@ss.hasPermi('system:member:add')")
    @Log(title = "新增会员", businessType = BusinessType.INSERT)
    @PostMapping
    @RepeatSubmit
    public AjaxResult add(@RequestBody SkiMember skiMember) {
        return toAjax(skiMemberService.insertSkiMember(skiMember));
    }

    /**
     * 修改会员
     */
    @PreAuthorize("@ss.hasPermi('system:member:edit')")
    @Log(title = "会员", businessType = BusinessType.UPDATE)
    @PutMapping
    @RepeatSubmit
    public AjaxResult edit(@RequestBody SkiMember skiMember) {
        return toAjax(skiMemberService.updateSkiMember(skiMember));
    }

    /**
     * 删除会员
     */
    @ApiOperation(value = "删除会员")
    @PreAuthorize("@ss.hasPermi('system:member:remove')")
    @Log(title = "删除会员", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(skiMemberService.deleteSkiMemberByIds(ids));
    }
}
